<?php
session_start();

include_once "src/controller/regmanagement/AccountManager.php";
include_once "src/model/Consultant.php";
include_once "src/model/ProvidedService.php";
//sleep(3);
try {
    $months = array();
    $months["January"] = 1;
    $months["February"] = 2;
    $months["March"] = 3;
    $months["April"] = 4;
    $months["May"] = 5;
    $months["June"] = 6;
    $months["July"] = 7;
    $months["August"] = 8;
    $months["September"] = 9;
    $months["October"] = 10;
    $months["November"] = 11;
    $months["December"] = 12;

    $providedServicesTemp1 = explode("&", $_POST["userServicesProvidedString"]);

    $providedServices = array();
    for ($i = 0; $i < count($providedServicesTemp1) - 1; $i++) {
        $providedServicesTemp2 = explode("-", $providedServicesTemp1[$i]);
        
        $tempServingSince1 = explode(", ", $providedServicesTemp2[1]);
        
        $tempServingSince = $tempServingSince1[1] . "/" . $months[$tempServingSince1[0]] . "/01";

        $providedServiceTemp = new ProvidedService($providedServicesTemp2[0], $tempServingSince);
        $providedServices[$i] = $providedServiceTemp;
    }

    $user = new Consultant();

    $user->setConsultantId($_POST["consultantId"]);
    $user->setEmail($_SESSION["email"]);
    $user->setPassword($_POST["password"]);
    $user->setAccountTypeId($_POST["accountTypeId"]);
    $user->setCompanyName($_POST["companyName"]);
    $user->setPhysicalAddress($_POST["physicalAddress"]);
    $user->setPhysicalCity($_POST["physicalCity"]);
    $user->setPhysicalStateId($_POST["physicalStateId"]);
    $user->setPhysicalZipCode($_POST["physicalZipCode"]);
    $user->setMailingAddress($_POST["mailingAddress"]);
    $user->setMailingCity($_POST["mailingCity"]);
    $user->setMailingStateId($_POST["mailingStateId"]);
    $user->setMailingZipCode($_POST["mailingZipCode"]);
    $user->setTelephone($_POST["telephone"]);
    $user->setTelephoneExt($_POST["telephoneExt"]);
    $user->setCellphone($_POST["cellphone"]);
    $user->setWebsite($_POST["website"]);
    $user->setServices($providedServices);
    $user->setServicesOfferedDescription($_POST["servicesOfferedDescription"]);
    $user->setK12ClienteleIndicator($_POST["k12ClienteleIndicator"]);
    $user->setHigherEducationClienteleIndicator($_POST["higherEducationClienteleIndicator"]);
    $user->setBackgroundDescription($_POST["backgroundDescription"]);
    $user->setEducationDescription($_POST["educationDescription"]);
    $user->setExperienceDescription($_POST["experienceDescription"]);
    $user->setComplaintIndicator($_POST["complaintIndicator"]);
    $user->setPendingLitigationIndicator($_POST["pendingLitigationIndicator"]);
    $user->setNoneIndicator($_POST["noneIndicator"]);
    $user->setProfileSubmittedIndicator($_POST["profileSubmittedIndicator"]);
    $user->setProfileFirstName($_POST["firstName"]);
    $user->setProfileLastName($_POST["lastName"]);
    $user->setProfileEmail($_POST["email"]);

    if (AccountManager::updateUserProfile($user)) {
        echo "1";
    } else {
        echo "0";
    }
    
} catch (Exception $e) {
    echo $e->getMessage();
}
?>
